package com.example.demo.common.page;

import java.io.Serializable;

/**
 * 分页请求参数
 */
public class PageRequest implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 当前页码 */
    private Integer pageNum = 1;
    
    /** 每页记录数 */
    private Integer pageSize = 10;
    
    /** 排序字段 */
    private String orderBy;
    
    /** 排序方式（asc/desc） */
    private String orderType;

    public Integer getPageNum() {
        return pageNum != null && pageNum > 0 ? pageNum : 1;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize != null && pageSize > 0 ? pageSize : 10;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }
    
    /**
     * 获取开始行
     */
    public Integer getStartRow() {
        return (getPageNum() - 1) * getPageSize();
    }
    
    /**
     * 获取排序语句
     */
    public String getOrderByClause() {
        if (orderBy != null && !orderBy.isEmpty()) {
            return orderBy + " " + (("desc".equalsIgnoreCase(orderType)) ? "desc" : "asc");
        }
        return null;
    }
} 